﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.SqlClient;

using JM.JCY.BusinessEntity;
using JM.JCY.Common;
using System.Data;

namespace JM.JCY.DataAccess
{
    public class UserManagementDA : JCYDataAccessBasecs
    {

        public DataSetUserManagement.T_DepartmentDataTable GetAllDepartment()
        {
            DataSetUserManagement.T_DepartmentDataTable dt = new DataSetUserManagement.T_DepartmentDataTable();
            base.Helper.Fill(dt, "P_GetAllDepartment_S");
            return dt;
        }

        public bool UpdateDepartmentSortOrder(string DeptName, int SortOrder)
        {
            if (base.Helper.ExecuteNonQuery("P_UpdateDepartmentSortOrderByDeptName_U", DeptName, SortOrder) == 1)
                return true;
            else
                return false;

        }

        public void UpdateDepartmentSortOrder(DataSetUserManagement.T_DepartmentDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public DepartmentTitleDataSet.T_DeptTitleDataTable GetDeptTitleList()
        {
            DepartmentTitleDataSet.T_DeptTitleDataTable dt = new DepartmentTitleDataSet.T_DeptTitleDataTable();
            base.Helper.Fill(dt, "P_GetDeptTitleList_S");
            return dt;
        }



        public int IsExistDept(string DeptName)
        {
            int count = 0;
            count = this.Helper.ExecuteScalar<int>("P_GetDeptCountByName_S", DeptName);
            return count;


        }

        public bool DelDeptById(int deptId)
        {
            if (base.Helper.ExecuteNonQuery("P_DeleteDeptById_D", deptId) == 1)
                return true;
            else
                return false;

        }

        public DataSetUserManagement GetDepartmentTitleById(int deptId)
        {
            DataSetUserManagement ds = new DataSetUserManagement();
            base.Helper.Fill(ds, new string[] { "T_Department" }, "P_GetDeptById_S", deptId);
            base.Helper.Fill(ds, new string[] { "T_JobTitle" }, "P_GetTitleByDeptId_S", deptId);
            return ds;
        }

        public DataSetUserManagement.T_JobTitleDataTable GetTitleByDeptId(int deptId)
        {
            DataSetUserManagement.T_JobTitleDataTable dt = new DataSetUserManagement.T_JobTitleDataTable();
            base.Helper.Fill(dt, "P_GetTitleByDeptId_S", deptId);
            return dt;
        }

        public DataSetUserManagement.T_UserInfoDataTable SearchUserInfo(string name, int deptId, int jobTitleId, string status)
        {
            DataSetUserManagement.T_UserInfoDataTable dt = new DataSetUserManagement.T_UserInfoDataTable();
            base.Helper.Fill(dt, "P_SearchUserInfo_S", name, deptId, jobTitleId, status);
            return dt;
        }

        public DepartmentTitleDataSet.T_DeptTitleDataTable GetDeptTitleByUserId(int userId)
        {
            DepartmentTitleDataSet.T_DeptTitleDataTable dt = new DepartmentTitleDataSet.T_DeptTitleDataTable();
            base.Helper.Fill(dt, "P_GetDeptTitleByUserId_S", userId);
            return dt;
        }


        public void CreateNewDepartment(DataSetUserManagement ds)
        {
            base.Helper.Update(ds);
        }

        // update by Hong Liang
        public FrameworkDataset.T_MyCommitteeDataTable GetMyCommittee(string userName)
        {
            FrameworkDataset.T_MyCommitteeDataTable dt = new FrameworkDataset.T_MyCommitteeDataTable();
            base.Helper.Fill(dt, "P_Committee_S_Mine", userName);
            return dt;
        }

        public DataSetUserManagement.T_DepartmentDataTable GetDeptById(int deptId, string deptName)
        {
            DataSetUserManagement.T_DepartmentDataTable dt = new DataSetUserManagement.T_DepartmentDataTable();
            base.Helper.Fill(dt, "P_Department_S_ById", deptId, deptName);
            return dt;

        }

        public DataSetUserManagement.T_UserInfoDataTable GetUser(int userId, string userName)
        {
            DataSetUserManagement.T_UserInfoDataTable dt = new DataSetUserManagement.T_UserInfoDataTable();
            base.Helper.Fill(dt, "P_UserInfo_S_ById", userId, userName);
            return dt;
        }

        public DepartmentTitleDataSet.T_DepartmentJobTitleDataTable GetUserDeptTitle(int userId)
        {
            var dt = new DepartmentTitleDataSet.T_DepartmentJobTitleDataTable();
            base.Helper.Fill(dt, "P_SearchUserInfo_DeptTitle", userId);
            return dt;
        }

        public void UpdateUserDept(DepartmentTitleDataSet.T_UserDepartmentDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public void UpdateUserJobTitle(DepartmentTitleDataSet.T_UserJobTitleDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public void UpdateUserInfo(DataSetUserManagement.T_UserInfoDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public DepartmentTitleDataSet.T_UserDepartmentDataTable GetUserDeptByUserId(int userId)
        {
            var dt = new DepartmentTitleDataSet.T_UserDepartmentDataTable();
            base.Helper.Fill(dt, "P_UserDepartment_S_ByUserId", userId);
            return dt;
        }

        public DepartmentTitleDataSet.T_UserJobTitleDataTable GetUserJobTiTleByUserId(int userId)
        {
            var dt = new DepartmentTitleDataSet.T_UserJobTitleDataTable();
            base.Helper.Fill(dt, "P_UserJobTitle_S_ByUserId", userId);
            return dt;
        }

        public DepartmentTitleDataSet.T_JobTitle_MemberDataTable GetUserJobtitle(int userId, int deptId)
        {
            var dt = new DepartmentTitleDataSet.T_JobTitle_MemberDataTable();
            base.Helper.Fill(dt, "P_UserDepartment_Jobtitle_S", userId, deptId);
            return dt;
        }

        public DepartmentTitleDataSet.T_Dept_MemberDataTable GetDepartmentMember(int deptId)
        {
            var dt = new DepartmentTitleDataSet.T_Dept_MemberDataTable();
            base.Helper.Fill(dt, "P_UserDepartment_Member_S", deptId);
            return dt;
        }

        public DepartmentTitleDataSet.T_UserInfo_PersonalDataTable GetUserForHome(int userId)
        {
            var dt = new DepartmentTitleDataSet.T_UserInfo_PersonalDataTable();
            base.Helper.Fill(dt, "P_UserInfo_S_forHome", userId);
            return dt;

        }

        public DepartmentTitleDataSet.T_User_Related_DeptDataTable GetUserRelatedDept(string userName)
        {
            var dt = new DepartmentTitleDataSet.T_User_Related_DeptDataTable();
            base.Helper.Fill(dt, "P_UserInfo_S_Dept", userName);
            return dt;
        }

        public DepartmentTitleDataSet.T_UserDepartmentDataTable GetUserDeptMatch(int userId, int deptId)
        {
            var dt = new DepartmentTitleDataSet.T_UserDepartmentDataTable();
            base.Helper.Fill(dt, "P_UserDepartment_Match", userId, deptId);
            return dt;
        }

        public DepartmentTitleDataSet.T_User_Dept_DataDataTable GetUserDept(int userId)
        {
            var dt = new DepartmentTitleDataSet.T_User_Dept_DataDataTable();
            base.Helper.Fill(dt, "P_UserDepartment_ByUserId", userId);
            return dt;
        }

        // for committee
        public CommitteeDataSet.T_CommitteeDataTable GetCommitteeById(int committeeId)
        {
            var dt = new CommitteeDataSet.T_CommitteeDataTable();
            base.Helper.Fill(dt, "P_Committee_S_ById", committeeId);
            return dt;
        }

        public CommitteeDataSet.T_Committee_MemberDataTable GetCommitteeMember(int committeeId)
        {
            var dt = new CommitteeDataSet.T_Committee_MemberDataTable();
            base.Helper.Fill(dt, "P_Committee_S_Member", committeeId);
            return dt;
        }

        public void UpdateCommittee(CommitteeDataSet.T_CommitteeDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public void UpdateUserComittee(CommitteeDataSet.T_UserCommitteeDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public CommitteeDataSet.T_UserCommitteeDataTable GetUserCommitteeById(int userCommitteeId)
        {
            var dt = new CommitteeDataSet.T_UserCommitteeDataTable();
            base.Helper.Fill(dt, "P_UserCommittee_S_ById", userCommitteeId);
            return dt;
        }

        public CommitteeDataSet.T_CommitteeDataTable GetCommitteeByName(string committeeName)
        {
            var dt = new CommitteeDataSet.T_CommitteeDataTable();
            base.Helper.Fill(dt, "P_Committee_S_ByName", committeeName);
            return dt;
        }

        public CommitteeDataSet.T_UserCommitteeDataTable GetUserCommitteeMatch(int userId, int committeeId)
        {
            var dt = new CommitteeDataSet.T_UserCommitteeDataTable();
            base.Helper.Fill(dt, "P_UserCommittee_Match", userId, committeeId);
            return dt;
        }

        public void UpdateDepartmentMemeberSortOrder(DepartmentTitleDataSet.T_UserDepartmentDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public DepartmentTitleDataSet.T_UserDepartmentDataTable GetUserDepartmentByDeptId(int deptId)
        {
            var dt = new DepartmentTitleDataSet.T_UserDepartmentDataTable();
            base.Helper.Fill(dt, "P_GetUserDepartmentByDeptId_S", deptId);
            return dt;
        }

        // contact
        public DepartmentTitleDataSet.T_User_ContactDataTable GetUserContactByName(string userName)
        {
            var dt = new DepartmentTitleDataSet.T_User_ContactDataTable();
            base.Helper.Fill(dt, "P_UserContact_S", userName);
            return dt;
        }

        public DepartmentTitleDataSet.T_User_ContactDataTable GetUserContactForHome(string userName, int count)
        {
            var dt = new DepartmentTitleDataSet.T_User_ContactDataTable();
            base.Helper.Fill(dt, "P_UserContact_S_ForHome", userName, count);
            return dt;
        }

        public DataSetUserManagement.T_UserInfoDataTable GetUserForSystem(int userId)
        {
            DataSetUserManagement.T_UserInfoDataTable dt = new DataSetUserManagement.T_UserInfoDataTable();
            base.Helper.Fill(dt, "P_UserInfo_S_ForSystem", userId);
            return dt;
        }

        public void CreateDeptMgr(UserInfoDataSet.T_DeptMgrDataTable dt)
        {
            base.Helper.Update(dt);
        }

        public void DeleteDeptMgrByUserName(string userName)
        {
             base.Helper.ExecuteNonQuery("P_DeleteDeptMgrByUser_D", userName);
        }

        public UserInfoDataSet.T_DeptMgrDataTable GetUserDeptMgr(string userName)
        {
            UserInfoDataSet.T_DeptMgrDataTable dt = new UserInfoDataSet.T_DeptMgrDataTable();
            base.Helper.Fill(dt, "P_GetUserDeptMgr_S", userName);
            return dt;
        }

        public void DeleteUserById(int userId)
        {
            base.Helper.ExecuteNonQuery("P_User_ById", userId);
        }
    }
}
